//
//  LoginRegisterService.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/7/20.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "LoginRegisterService.h"
#import "GFXNetworkHandle.h"
#import "SZLAccountHelper.h"

NSString * const LoginUrl = @"user/login"; //登录
NSString * const VerfyCodeUrl = @"sms/send/code"; //验证码
NSString * const RegisterUrl = @"user/register"; //注册
NSString * const ForgetPswUrl = @"user/forgetLoginPwd"; //忘记密码


NSString * const LoginRegister = @"user/registerAndLogin/send"; //新注册登录
NSString * const WriteInfo = @"userCard/update/info/send"; //引导用户注册

NSString * const AgreeProtocolUrl = @"agreement/register"; //合作协议
NSString * const ShopCreateUrl = @"auth/shop/create"; //注册商家
NSString * const ChangeSellerInfoUrl = @"auth/shop/info/update"; //已注册商家修改资料

@implementation LoginRegisterService

+ (void)getVerfyCodeWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:VerfyCodeUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)loginRegisterWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle] post:LoginRegister params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            [SZLAccountHelper updateUserWithLogin:json[@"result"] needSave:YES];
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}
+ (void)writeInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSString *token))response
{
    [[GFXNetworkHandle shareHandle] post:WriteInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"],json[@"result"]);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)registerWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle] post:RegisterUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            [SZLAccountHelper updateUserWithLogin:json[@"result"] needSave:YES];
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)forgetWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle] post:ForgetPswUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)loginWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle] post:LoginUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            [SZLAccountHelper updateUserWithLogin:json[@"result"] needSave:YES];
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)shopCreateWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle] post:ShopCreateUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)changeShopInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle] post:ChangeSellerInfoUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}


@end
